-
Notifications
You must be signed in to change notification settings - Fork 345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try to resolve container.name from the injected agent args #1319
Conversation
Signed-off-by: Megrez Lu <[email protected]>
Signed-off-by: Megrez Lu <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #1319 +/- ##
==========================================
+ Coverage 87.35% 87.41% +0.05%
==========================================
Files 89 89
Lines 4999 5021 +22
==========================================
+ Hits 4367 4389 +22
Misses 467 467
Partials 165 165
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @rubenvp8510
pkg/inject/sidecar.go
Outdated
@@ -378,3 +386,12 @@ func EqualSidecar(dep, oldDep *appsv1.Deployment) bool { | |||
oldDepContainer := oldDep.Spec.Template.Spec.Containers[oldDepIndex] | |||
return reflect.DeepEqual(depContainer, oldDepContainer) | |||
} | |||
|
|||
func parseAgentTags(args []string) []string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we follow the refactoring mentioned above, we might not need this. The reason is that we'd have a consistent result for the map, as long as the container name doesn't change. Once it changes, we want this new name to be used in the map/args.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I partially agree for this point. Suppose we have a deployment with one single container at the very beginning, of course we can readily deduce the container.name
. Then we inject several sidecars base on the annotations, let's say, istio-proxy and jaeger-agent, we will finally have three containers in this deployment.
At the second time, even if we are able to filter the jaeger-agent out, we still have two containers from which we are not able to pick the correct container.name
without a prior. So I think it is still necessary to parse the Tags / Args from the existing agent container.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should really leave the container.name
out if we have more than one container (not counting the Jaeger Agent one). It's certainly possible that traces are coming from both containers in that case, so, the annotation will be wrong. Reusing the container name from an older version of the pod doesn't seem right to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should really leave the
container.name
out if we have more than one container (not counting the Jaeger Agent one). It's certainly possible that traces are coming from both containers in that case, so, the annotation will be wrong. Reusing the container name from an older version of the pod doesn't seem right to me.
I understand your argument and I think it is quite reasonable. But the deployment may still probably restart once if we inject more than one sidecar. That would cause a serious problem in a large cluster (we have ~500 deployments in our production cluster). How can we prevent from this situation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will happen only if you didn't have another container before, but now you have, right? The only way to prevent that, from what I can see, is to add the agent sidecar manually, so that the operator won't manage this container for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically, I am concerned with the scenario with two operators: one is jaeger-operator
, the other is istio-operator
.
Emm, what about adding an annotation to specify the container-name, if the user want to set the name explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users can do that already by adding env vars to their own container (JAEGER_TAGS). The tags we add to the sidecar container are ones that we add based on information we can infer from the env.
Signed-off-by: Megrez Lu <[email protected]>
I try to refactor the code following the comment made by @jpkrohling
Still a question, do we need to remove |
go.mod
Outdated
@@ -7,7 +7,6 @@ require ( | |||
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 | |||
github.com/go-openapi/spec v0.19.8 | |||
github.com/googleapis/gnostic v0.3.1 | |||
github.com/miekg/dns v1.1.35 // indirect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's up with the changes to go.mod and go.sum ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reverted all changes to go.mod
and go.sum
. But may be this is an indirect dependency, so it will be cleaned by go mod tidy
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be. Once this gets merged, would you like to run a go mod tidy
against master and seeing if there are differences in the go.mod?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I would like to have a try.
Signed-off-by: Megrez Lu <[email protected]>
Signed-off-by: Megrez Lu <[email protected]>
Signed-off-by: Megrez Lu <[email protected]>
Signed-off-by: Megrez Lu <[email protected]>
Signed-off-by: Megrez Lu <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. @rubenvp8510, please take a look as well. Once you give your approval, I'll merge this.
assert.Contains(t, agentTags, "container.name=only_container") | ||
agentTagsMap := parseAgentTags(dep.Spec.Template.Spec.Containers[1].Args) | ||
assert.Contains(t, agentTagsMap, "container.name") | ||
assert.Equal(t, agentTagsMap["container.name"], "only_container") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are changing this PR for some other reason, you might want to remove the Contains
, as the Equals
assertion already covers it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right. Unnecessary Contains
Removed. Also fix the same issue in two other places.
Signed-off-by: Megrez Lu <[email protected]>
Signed-off-by: Megrez Lu <[email protected]>
Another problem may possibly come from the different logic in But in the IMO, it will also cause unstable status. |
Great catch. Would you like to change this PR here to align the logic? |
Sure. And I prefer not to exclude the agent from the container list since we can already reach convergence even if we inject the agent twice. What's your opionion? |
I'm not quite sure I understand what you mean, but send the code and I'll review it. |
Signed-off-by: Megrez Lu <[email protected]>
I have aligned |
This looks good to me. Good refactoring! |
Resolve #1318